import sqlite3

# 连接数据库
conn = sqlite3.connect('../temp/example.db')

# 创建一个游标对象
cursor = conn.cursor()

# 创建一个表
cursor.execute('''CREATE TABLE stocks
             (date text, trans text, symbol text, qty real, price real)''')

# 插入一行数据
cursor.execute("INSERT INTO stocks VALUES ('2023-07-05','BUY','RHAT',100,35.14)")

# 提交事务
conn.commit()

# 查询数据
cursor.execute("SELECT * FROM stocks")
rows = cursor.fetchall()
for row in rows:
    print(row)

# 更新数据
cursor.execute("UPDATE stocks SET price = 40.0 WHERE symbol = 'RHAT'")
conn.commit()

# 关闭连接
conn.close()
